import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/domain/widgets/flow_item.dart';
import 'package:flutter_syt/domain/widgets/network_load_image.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:flutter_syt/utils/global_date_time_format.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

class FlowWaterfallItem extends StatefulWidget {
  FlowItemEntity item;
  FlowWaterfallItem(this.item);
  @override
  FlowWaterfallItemState createState() => FlowWaterfallItemState();
}

class FlowWaterfallItemState extends State<FlowWaterfallItem> {
  var zhLang = true;
  var local =
      appContext.storage.getString("storyLocal") ?? Intl.getCurrentLocale();
  @override
  Widget build(BuildContext context) {
    if (local.contains('zh')) {
      zhLang = true;
    } else {
      zhLang = false;
    }
    var aspectRatio = widget.item.width / widget.item.height > 0
        ? widget.item.width / widget.item.height
        : 0.5;
    // if (condition) {

    // }
    return GestureDetector(
      onTap: ClickUtils.debounce(
          () => RouteManager.push(context, widget.item.linkUrl)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          AspectRatio(
            // aspectRatio: widget.item.width / widget.item.height,
            aspectRatio: aspectRatio,
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(const Radius.circular(12)),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(12),
                child: NetworkLoadImage.loadNetworkImage(
                  widget.item.imageUrl,
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 8),
            child: Text(
              '${widget.item.text}',
              maxLines: 2,
              softWrap: false,
              textAlign: TextAlign.left,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Color(0xff000000),
                fontSize: 16,
                // fontWeight: FontWeight.w300,
                fontFamily: 'PingFang SC',
              ),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 10),
            child: Text(
              zhLang == true
                  ? formatDate(widget.item.createTime)
                  : enFormatDate(widget.item.createTime),
              maxLines: 1,
              softWrap: false,
              textAlign: TextAlign.left,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Colors.black.withOpacity(0.4),
                fontSize: 11,
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(FlowWaterfallItem oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}
